<?php

namespace api\modules\app\controllers;

use api\common\helpers\Constant;
use api\components\BaseController;
use InvalidArgumentException;
use Yii;

class UserController extends BaseController
{
    public function actionChangeDepartment()
    {
        $params = $this->getParams('organization');
        $user = $this->getUser();
        foreach ($user['organizations'] as $organization) {
            if ($organization['organization_id'] == $params['organization_id']) {
                $selected = $organization;
            }
        }

        if (empty($selected)) {
            throw new InvalidArgumentException('所选组织不存在');
        }

        $key = Constant::USER_SELECTED_ORG . $user['id'];
        Yii::$app->redisCache->set($key, $selected);

        return true;
    }
}
